<template>
    <section class="modlude">
        <el-form :inline="true" :model="formSearch" class="form_inline" label-width="100px">
            <el-form-item label="选择项目" size="small" prop="projectId">
                <el-select v-model="formSearch.projectId" placeholder="请选择项目" >
                    <el-option v-for="item in xqTree" :label="item.name" :value="item.id" :key="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="设备名称" size="small">
                <el-input v-model="formSearch.devName" placeholder="请输入设备名称" clearable></el-input>
            </el-form-item>
            <el-form-item label="开始时间" size="small">
                <el-date-picker v-model="formSearch.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="开始时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间" size="small">
                <el-date-picker v-model="formSearch.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="结束时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button size="small" @click="sendData">查 询</el-button>
            </el-form-item>
        </el-form>
    </section>
</template>

  <script>
import paging from '../../components/paging.vue';
import {
    delCar,
    xqSelectList,
    orgTree,
    getCarDevLogList
} from '../../url/api';
export default {
    data() {
        return {
            checkStrictly: false,
            bindRole: {},
            showmenuList: [],
            menuList: [],
            option1: [],
            xqTree: [],
            isAddorUpdate: 1, //1添加、2修改
            formSearch: {
                projectId: '',
                current: 1,
                size: 10,
            },
            formData: [], //数据
            deleBatch: [], //删除数据
            formUpdate: {}, //修改表单
            total: 0, //数据总数
            pages: 0, //页面总数
            addDialog: false,
            updateDialog: false,
            dialog: false,
            replyType: 1, //1。单个回复 2.批量回复
            formPush: {},
            dataTree: [],
            defaultProps: {
                //树状图key定义
                children: 'data',
                label: 'name',
            },
            defaultProps2: {
                children: 'children',
                label: 'name',
                value: 'id',
                expandTrigger: 'hover',
                checkStrictly: true,
            },
            reply: '',
            moduleInfor: {},
            rules: {
                name: [{ required: true, message: '该项不能为空' }],
                type: [
                    {
                        required: true,
                        message: '该项不能为空',
                        trigger: 'blur',
                    },
                ],
                projectId: [
                    {
                        required: true,
                        message: '该项不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            imageUrl: '',
        };
    },
    methods: {
        sendData() {
            console.log('emit加载');
            this.Bus.$emit('sendTableData5', {
                formSearch: this.formSearch,
                // total:this.total
            });
        },
        getList(){
            getCarDevLogList(this.formSearch).then((res)=>{
                console.log(res);
                if(res.data.ok){
                   this.formData = res.data.data.records.filter((item)=>{
                return item
                })
                this.total = res.data.data.total;
                // this.sendData();
            }else{
          this.$message(res.data.msg);
        }
            })
        },
        getInit() {
            xqSelectList({}).then((res) => {
                //项目选择列表
                console.log(res);
                if (res.data.ok) {
                    this.xqTree = res.data.data;
                    this.formSearch.projectId = this.xqTree[0].id;
                    this.getList();
                }
            });
            let org_tree = {
                name: '',
                status: 1,
            };
            orgTree(org_tree).then((res) => {
                //获取组织列表
                console.log(res);
                if (res.data.ok) {
                    this.dataTree = res.data.data;
                }
            });
        },
        addList(addList) {
            //添加树状图node节点
            this.$refs[addList].validate((valid) => {
                if (valid) {
                    this.addDialog = false;

                    this.addDialog = false;
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        updateList(formName) {
            //修改
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if (this.formUpdate.gmtCreate) {
                        delete this.formUpdate.gmtCreate;
                    }
                    let params = this.formUpdate;
                } else {
                    console.log('error submit!!');
                    return false;
                }
                this.updateDialog = false;
            });
        },
        updateShowBox(item) {
            //修改东西弹窗
            // this.formUpdate = JSON.parse(JSON.stringify(item));
            this.formUpdate = {
                id: item.id,
            };
            this.updateDialog = true;
            console.log(this.formUpdate);
        },
        deleInfor(ids) {
            //删除
            let arrId = [];
            if (ids) {
                arrId.push(ids);
            } else {
                if (this.deleBatch.length != 0) {
                    this.deleBatch.filter((item) => {
                        arrId.push(item.carId);
                        return item;
                    });
                }
            }
            this.$confirm('确认删除吗？')
                .then((_) => {
                    delCar(arrId).then((res) => {
                        console.log(res);
                        if (res.data.ok) {
                            this.$message('删除成功');
                            this.getlist();
                        }
                    });
                })
                .catch((_) => {});
        },   
        handleSelectionChange(val, self) {
            //多选
            this.deleBatch = val;
            console.log(this.deleBatch);
        },
        handleCurrentPage(val) {
            //页码改变
            this.formSearch.current = val;
            this.getList();
        },
    },
    mounted() {
        this.getInit();
    },
    components: {
        paging,
    },
};
</script>
<style scoped lang='scss'>
.module > .form_demo /deep/ .el-date-editor.el-input{
    width: 156px;
}
.form_inline /deep/ .el-date-editor.el-input,
.el-date-editor.el-input__inner {
    width: 156px;
}
.cont_box {
    width: 100%;
    display: flex;
}
.cont_box_left,
.cont_box_right {
    flex: 1;
    background: transparent;
    padding: 10px;
}
.cont_box_left {
    margin-right: 10px;
}
.margin10 {
    margin-bottom: 10px;
}
.marginRight {
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
}
.cont_box_right .el-form-item {
    margin-bottom: 20px;
}
</style>